using System;
using System.Transactions;
using NServiceBus;

namespace EmailGateway
{
    public class NServiceBusWayOfDoingThings
    {
private readonly IRepository repository;
private readonly IBus bus;

public void CreateUser(string userName, string password)
{
    using (var transaction = new TransactionScope())
    {
        var user = new User
        {
            UserName = userName,
            Password = password
        };

        repository.Save(user);

        var emailRequest = new SendEmailRequest
                               {
                                   ToAdress = userName,
                                   Subject = "Account created",
                                   Body = "Please click the following link to activate account: " +
                                          "http://mysite/confirm&id=" + user.Id
                               };

        bus.Send(emailRequest);


        transaction.Complete();
    }
}

    }
}